# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=scons
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.1.0
pkgrel=3
pkgdesc="Extensible Python-based build utility (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('MIT')
url="https://scons.org"
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/${_realname}/${_realname}/archive/${pkgver}.tar.gz"
        "0001-fix-mingw-path.patch"
        "0002-fix-missing-man-pages.patch")
sha256sums=('7662af76d971bae3e9c01e6d025d4ff0f547b64cac081298fc19015c9c242311'
            '4416b87da2d7e2879d6f2fd13796887b0a0de3dfffb9be3ec2f565f794a72048'
            '10d673ed98436501a0957704d079af3931633a296cc08b3d3a6708006c903f49')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-fix-mingw-path.patch"
  patch -Np1 -i "${srcdir}/0002-fix-missing-man-pages.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1

  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/scons-configure-cache-script.py"
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/scons-script.py"
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/sconsign-script.py"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
